package org.edu.modules.sbzc.fund.service.impl;

import cn.hutool.core.convert.Convert;
import org.edu.common.base.BasePageDto;
import org.edu.common.base.BaseServiceImpl;
import org.edu.common.utils.ConvertUtils;
import org.edu.common.base.BaseServiceImpl;
import org.edu.modules.sbzc.fund.enums.AssetStatusEnum;
import org.edu.modules.sbzc.fund.mapper.VeSbzcZcRetireMapper;
import org.edu.modules.sbzc.fund.entity.VeSbzcZcRetire;
import org.edu.modules.sbzc.fund.dto.VeSbzcZcRetireDto;
import org.edu.modules.sbzc.fund.service.VeSbzcZcAssetService;
import org.edu.modules.sbzc.fund.service.VeSbzcZcRetireService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 实现类
 */
@Service
public class VeSbzcZcRetireServiceImpl extends BaseServiceImpl<VeSbzcZcRetire, VeSbzcZcRetireMapper> implements VeSbzcZcRetireService {

    /**
     * VeSbzcZcAssetService
     */
    @Autowired
    private VeSbzcZcAssetService veSbzcZcAssetService;

    public IPage<VeSbzcZcRetireDto> pageDto(BasePageDto page, @Param(Constants.WRAPPER) Wrapper queryWrapper){
        return mapper.pageDto(page,queryWrapper);
    }
    /**
    * 查询实体类
    */
    public VeSbzcZcRetireDto findDtoById(String id) {
        VeSbzcZcRetire entity = super.findById(id);
        VeSbzcZcRetireDto dto = ConvertUtils.convertToDto(entity, VeSbzcZcRetireDto.class);
        return dto;
    }

    /**
    * 新增或者修改
    */
    public void insertOrUpdate(VeSbzcZcRetireDto dto,Boolean isAdd){
        if(isAdd){
            super.insert(dto);
        }else{
            super.update(dto);
        }
        //更改固资状态为报废
        veSbzcZcAssetService.updateAssetStatus(Convert.toStr(dto.getAssetId()), AssetStatusEnum.RETIRE.getValue());
    }

}
